<html xmlns:th="http://www.thymeleaf.org"
      xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity4">
<body>
<form id="informationForm" role="form" method="post" action="information/update">
    <input type="hidden" name="id" id="informationId" th:value="${entity.id}"/>
    <div class="form-group">

        <div class="form-group">
            <label for="title">资讯标题:</label>
            <input type="text" class="form-control" name="title" id="title" th:value="${entity.title}"
                   placeholder="请输入资讯标题"/>
        </div>
        <div class="form-group">
            <label for="consultContent">资讯内容:</label>
            <input type="text" class="form-control" name="consultContent" th:value="${entity.consultContent}"
                   id="consultContent" placeholder="请输入资讯内容"/>
        </div>
        <div class="form-group">
            <label for="type">咨询类型:</label>
            <select class="form-control" name="type" id="type">
            </select>
        </div>
    </div>
</form>
<script th:inline="javascript">
    <![CDATA[
    $(function () {
        $.post("dict/getType", {type: "INFORMATION_TYPE"},
            function (r) {
                var infotype=[[${entity.type}]];
                for (var i = 0; i < r.data.length; i++) {
                    if(r.data[i].value==infotype){
                        $("#type", window.top.document).append("<option selected=true  value=" + r.data[i].value + ">" + r.data[i].text + "</option>");
                    }else{
                    $("#type", window.top.document).append("<option value=" + r.data[i].value + ">" + r.data[i].text + "</option>");
                }}
            });
        $('#informationForm', window.top.document).bootstrapValidator({
            message: 'This value is not valid',
            feedbackIcons: {
                valid: 'glyphicon glyphicon-ok',
                invalid: 'glyphicon glyphicon-remove',
                validating: 'glyphicon glyphicon-refresh'
            },
            fields: {
                title: {
                    validators: {
                        notEmpty: {
                            message: '资讯标题不能为空'
                        }
                    }
                },

                consultContent: {
                    validators: {
                        notEmpty: {
                            message: '资讯内容不能为空'
                        }
                    }
                }
            }
        });

        // 绑定dialog的确定按钮的监听事件
        $("#btnOk", window.top.document).click(function () {
            $("#btnOk", window.top.document).attr("disabled", true);
            var bootstrapValidator = $("#informationForm", window.top.document).data('bootstrapValidator');
            bootstrapValidator.validate();
            if (bootstrapValidator.isValid()) {
                $.post($("#informationForm", window.top.document).attr('action'), $("#informationForm", window.top.document).serialize(), function (e) {
                    if (e.result) {
                        refreshDoQuery();
                    } else {
                        window.Ewin.alert({message: '修改数据失败!'});
                    }
                    $("#btnOk", window.top.document).attr("disabled", false);
                })
            } else {
                $("#btnOk", window.top.document).attr("disabled", false);
            }
        });

        // 重新刷新当前查询页的数据
        function refreshDoQuery() {
            var iframes = $(window.parent.document).contents().find(".J_iframe");
            for (var i = 0; i < iframes.length; i++) {
                if ($(iframes[i]).css("display") == 'inline') {
                    $('.modal-dialog', window.top.document).parent('div').remove()
                    $('body', window.top.document).find('.modal-backdrop').remove();
                    iframes[i].contentWindow.doQuery();
                    break;
                }
            }
        }
    })
    ]]>
</script>
</body>
</html>